<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
    <title>枣强通行码</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .wrap {
            padding-top: 50px;
        }

        .btn {
            width: 260px;
            height: 50px;
            line-height: 50px;
            position: absolute;
            left: 50%;
            margin-left: -130px;
            margin-top: 50px;
            background: #265DA4;
            color: #fff;
            text-align: center;
            border-radius: 4px;
            font-size: 18px;
        }
        
    </style>
</head>

<body>
    <script src="./jquery/jquery.min.js"></script>
    <script src="./layui/layui.js"></script>
    <script src="./api/api.js?v=01"></script>
    <script>
        // 根据code获取用户是否注册  http://39.98.51.187:8899/ymtUser/checkUser
        $.ajax({
            url: ymt_api + "/ymtUser/checkUser",
            type: "post",
            data: {
                wxcode: getQueryVariable('code'),
            },
            success: function (res) {
                console.log(res)
                if (res.code == 1) {
                    // 用户存在
                    // res.data是入口的中文名字(例如:例如安平县城市管理综合行政执法局)
                    document.body.innerHTML = `<div class="wrap">
        <div style="text-align: center;margin-top: 20px;">
            <img src="./images/oks.png?v=01" alt="" width="200px">
        </div>
        <div style="text-align: center;margin-top: 50px;font-size: 20px;font-weight: bolder;">您已注册成功,请勿重复注册!</div>
        <div>
            <div class="btn" onclick="javascript:history.back(-1);">返回首页</div>
        </div>
    </div>`
                } else {
                    // 用户不存在
                    window.location.href = encodeURI(
                        'http://user.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url=http://hesuan.city1000.cn/zqpublic/register.html&data=0'
                    )
                }
            },
            error: function (err) {

            }
        })
        // 拿到码上的值,带到下一个页面
        function getQueryVariable(variable) {
            // 参数 window.location.search
            var query = decodeURI(window.location.search.substring(1))
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return (false);
        }
    </script>
</body>

</html>